package com.bestcem.xm.user.dao.impl;

import com.bestcem.xm.user.dao.OrganizationQuotainfoDao;
import com.bestcem.xm.user.dao.mapper.OrganizationQuotainfoMapper;
import com.bestcem.xm.user.entity.mysql.OrganizationQuotainfo;
import com.bestcem.xm.user.entity.pojo.OrganizationQuotainfoDO;
import com.bestcem.xm.user.entity.pojo.QuotaInfoQueryDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.OrganizationQuotainfoConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公司限额统计
 *
 * @author jishuo.yan <jishuo.yan@idiaoyan.com>
 * @date 2022/3/21 14:14
 */
@Repository
public class OrganizationQuotainfoDaoImpl implements OrganizationQuotainfoDao {

    @Resource
    private OrganizationQuotainfoMapper organizationQuotainfoMapper;

    @Resource
    private OrganizationQuotainfoConvert organizationQuotainfoConvert;

    @Override
    public String insertSelective(OrganizationQuotainfoDO organizationQuotainfoDO) {
        OrganizationQuotainfo organizationQuotainfo = organizationQuotainfoConvert.doToEntity(organizationQuotainfoDO);
        DataBaseUtil.setCreateAndUpdateTime(organizationQuotainfo);
        organizationQuotainfo.setQuotainfoId(DataBaseUtil.generateId());
        organizationQuotainfoMapper.insertSelective(organizationQuotainfo);
        return organizationQuotainfo.getQuotainfoId();
    }

    @Override
    public Integer updateByPrimaryKeySelective(OrganizationQuotainfoDO organizationQuotainfoDO) {
        return organizationQuotainfoMapper.updateByPrimaryKeySelective(organizationQuotainfoConvert.doToEntity(organizationQuotainfoDO));
    }

    @Override
    public List<OrganizationQuotainfoDO> selectBySelective(OrganizationQuotainfoDO organizationQuotainfoDO) {
        List<OrganizationQuotainfo> organizationQuotainfos = organizationQuotainfoMapper.selectBySelective(organizationQuotainfoConvert.doToEntity(organizationQuotainfoDO));
        return organizationQuotainfoConvert.entitysToDos(organizationQuotainfos);
    }

    @Override
    public List<OrganizationQuotainfoDO> listQuataInfo(QuotaInfoQueryDO quotaInfoQueryDO) {
        List<OrganizationQuotainfo> organizationQuotainfos = organizationQuotainfoMapper.listQuataInfo(quotaInfoQueryDO);
        return organizationQuotainfoConvert.entitysToDos(organizationQuotainfos);
    }

    @Override
    public long countQuataInfo(QuotaInfoQueryDO quotaInfoQueryDO) {
        return organizationQuotainfoMapper.countQuataInfo(quotaInfoQueryDO);
    }

    @Override
    public List<OrganizationQuotainfoDO> selectByQuery(QuotaInfoQueryDO quotaInfoQueryDO, List<String> orgList, Integer currentPage, Integer size) {
        List<OrganizationQuotainfo> orgQuotaInfos = organizationQuotainfoMapper.selectByQuery(quotaInfoQueryDO, orgList, (currentPage-1) * size, size);
        return organizationQuotainfoConvert.entitysToDos(orgQuotaInfos);
    }

    @Override
    public long countByOrgId(String orgId) {
        return organizationQuotainfoMapper.countByOrgId(orgId);
    }

    @Override
    public OrganizationQuotainfoDO getByOrgId(String orgId) {
        return organizationQuotainfoConvert.entityToDo(organizationQuotainfoMapper.getByOrgId(orgId));
    }

    @Override
    public Integer updateQuotaConsumption(OrganizationQuotainfoDO organizationQuotainfoDO) {
        return organizationQuotainfoMapper.updateQuotaConsumption(organizationQuotainfoConvert.doToEntity(organizationQuotainfoDO));
    }

    @Override
    public List<OrganizationQuotainfoDO> listPageByOrgId(String orgId, Integer currentPage, Integer size) {
        List<OrganizationQuotainfo> orgQuotainfos = organizationQuotainfoMapper.listPageByOrgId(orgId, (currentPage-1) * size, size);
        return organizationQuotainfoConvert.entitysToDos(orgQuotainfos);
    }
}
